//
//  GGlifeViewController.m
//  Gunterapple
//
//  Created by 热带雨林 on 2020/3/30.
//  Copyright © 2020 热带雨林. All rights reserved.
//

#import "GGlifeViewController.h"
#import "ZFBMomentModel.h"
#import "ZFBMomentCell.h"
#import "ZFBMomentWithoutImageCell.h"
#import "NSArray+URLAddtion.h"

static NSString *cellID = @"cellID";
static NSString *cellImageID = @"cellImageID";

@interface GGlifeViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableViwe;
@property (nonatomic, strong) NSMutableArray <ZFBMomentModel *>*dataArray;
@property (nonatomic, strong) ZFBMomentModel *model;
@end

@implementation GGlifeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
    self.title = @"生活圈";
    [self.view addSubview:self.tableViwe];
    //设置预估行高
//    self.tableViwe.rowHeight = 200;
//    self.tableViwe.estimatedRowHeight = UITableViewAutomaticDimension;
    self.tableViwe.estimatedRowHeight = 200;
    self.tableViwe.rowHeight = UITableViewAutomaticDimension;
    [self.tableViwe registerClass:[ZFBMomentCell class] forCellReuseIdentifier:cellImageID];
    [self.tableViwe registerClass:[ZFBMomentWithoutImageCell class] forCellReuseIdentifier:cellID];
    
}
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//    return self.dataArray.count;
//}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    self.model = self.dataArray[indexPath.row];
    if(![self.model.picture isEqualToString:@""]){
        ZFBMomentCell *cell = [tableView dequeueReusableCellWithIdentifier:cellImageID forIndexPath:indexPath];
        cell.model = self.model;
        return cell;
    }else{
        ZFBMomentWithoutImageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
        cell.model = self.model;
        return cell;
    }
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    cell.textLabel.text = self.model.name;
    return cell;
}
- (void)loadData{
    self.dataArray = [NSArray gg_arrayModelWithPlistName:@"moments.plist" withClassName:@"ZFBMomentModel"].mutableCopy;
}
#pragma mark - lazy
- (UITableView *)tableViwe{
    if(!_tableViwe){
        _tableViwe = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)) style:UITableViewStylePlain];
        _tableViwe.delegate = self;
        _tableViwe.dataSource = self;
    }
    return _tableViwe;
}
- (NSMutableArray *)dataArray{
    if(!_dataArray){
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
